#include "UIThread.h"


UIThread::UIThread(QueryResultList* list,MYSQL* mysql,EditNotebook* editNotebook,const wxString query,QueryResult* cur,QueryResult* r,
		 ResultNotebook* result,wxStatusBar* s_bar,wxChoice* currentDbChoice,Edit* log,int& type,ResultArray& array,fetch_callback fc):
wxThread(),resultList(list),mysql(mysql),query(query),cur(cur),r(r),
result(result),s_bar(s_bar),currentDbChoice(currentDbChoice),log(log),type(type),array(array),editNotebook(editNotebook){
	this->fc = fc;
}

void* UIThread::Entry(){
	
	wxDateTime start = wxDateTime::UNow();
	float fc_time = fc(array,mysql,query,s_bar,this->resultList,this->cur,this->r);
    wxString sb;
    sb.Printf(wxT("Fetching data: %.5f sec"),fc_time);
    s_bar->SetStatusText(sb,4);
	return NULL;
}

void UIThread::OnExit() {
	wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, ID_LOAD_RESULT );
	LoadEventData* data = new LoadEventData(array,mysql,query,type);
    event.SetClientData( data );
    wxPostEvent( result->GetParent(), event );
}
